import { FC, ReactNode } from 'react';
import { Navigate, useLocation } from 'react-router-dom';

interface Props {
    children: ReactNode;
}

const AuthRoute: FC<Props> = ({ children }) => {
    const location = useLocation();

    // 这里可以根据你的实际情况来判断用户是否登录
    const isLogin = localStorage.getItem('token');

    if (!isLogin) {
        // 未登录时重定向到登录页，并记录原始要访问的路径
        return <Navigate to="/login" state={{ from: location }} replace />;
    }

    return <>{children}</>;
};

export default AuthRoute; 